package org.example.stream;

import org.example.entity.Hero;

import java.util.Comparator;
import java.util.stream.Stream;

public class Stream07 {
    public static void main(String[] args) {
        Stream<Hero> heroStream = Stream.of(
                new Hero("独孤求败", 100),
                new Hero("令狐冲", 90),
                new Hero("风清扬", 98),
                new Hero("东方不败", 98),
                new Hero("方证", 92),
                new Hero("任我行", 92),
                new Hero("冲虚", 90),
                new Hero("向问天", 88),
                new Hero("不戒", 88)
        );
//        System.out.println(heroStream.reduce((t1, t2) -> t1.getStrength() > t2.getStrength() ? t1 : t2));

//        System.out.println(heroStream.reduce(new Hero("-", -1), (t1, t2) -> t1.getStrength() > t2.getStrength() ? t1 : t2));
        // 求高手总数
//        System.out.println(heroStream.map(h -> 1).reduce(0, (i, j) -> i + j));
//        System.out.println(heroStream.map(h -> 1).reduce(0, Integer::sum));
//        System.out.println(heroStream.count());
        System.out.println(heroStream.max(Comparator.comparingInt(Hero::getStrength)));
    }
}
